import numpy as np

t1 = np.arange(24).reshape(4, 6)
print("t1: ", t1)

t1 = t1.astype(float)
t1[3, 3] = np.nan
print("t1=", t1)

print(np.nan == np.nan)
print(np.nan != np.nan)
print(type(np.inf))  # <class 'float'>
print(type(np.nan))  # <class 'float'>

t1[:, 0] = 0
print("t1=", t1)
print("t1个数=", np.count_nonzero(t1))
print("t1!=t1:", t1 != t1)
print("判断nan的个数=", np.count_nonzero(t1 != t1))  # 判断nan的个数
print("np.isnan(t1)=", np.isnan(t1))
print("判断nan的个数=", np.count_nonzero(np.isnan(t1)))  # 判断nan的个数

print("求和1=",np.sum(t1))  # 求和
print("求和2=",t1.sum(axis=0))
print("求和3=",t1.mean(axis=0))
# print("求和4=",t1.max(axis=0)) # TODO 以下函数有问题的 求出axis最大值
# print("求和5=",t1.min(axis=0))
# print("求和6=",np.ptp(t1, axis=0))

t1[np.isnan(t1)] = 0  # nan替换为0
print("t1=", t1)
print(np.sum(t1))

t2 = np.arange(12).reshape(3, 4)
print("t2: ", t2)
print(np.sum(t2, axis=0))
print(np.sum(t2, axis=1))
